<!DOCTYPE html>
<html lang="en" xmlns:th="www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>list test</title>
</head>
<body>

<table border="1">
    <tr>
        <td>id</td>
        <td>state.index</td>
        <td>name</td>
        <td>state.count</td>
        <td>code</td>
        <td>state.size</td>
        <td>tag</td>
        <td>rangeRate</td>
        <td>monthRangeRate</td>
    </tr>
    <tr th:each="lucky,state: ${luckyList}">
        <td th:text="${lucky.id}"></td>
        <td th:text="${state.index}"></td>
        <td th:text="${lucky.name}"></td>
        <td th:text="${state.count}"></td>
        <td th:text="${lucky.tag}"></td>
        <td th:text="${state.size}"></td>
        <td th:text="${lucky.code}"></td>
        <td th:text="${lucky.rangeRate}"></td>
        <td th:text="${lucky.monthRangeRate}"></td>
    </tr>
</table>

<table border="2">
    <tr>
        <td>id</td>
        <td>name</td>
        <td>code</td>
        <td>tag</td>
        <td>rangeRate</td>
        <td>monthRangeRate</td>
    </tr>
    <tr th:object="${lucky}">
        <td th:text="*{id}"></td>
        <td th:text="*{name}"></td>
        <td th:text="*{code}"></td>
        <td th:text="*{tag}"></td>
        <td th:text="*{rangeRate}"></td>
        <td th:text="*{monthRangeRate}"></td>
    </tr>
</table>

<div>
    <h2>#{}测试</h2>
    <h2 th:text="#{message}"></h2>
</div>

<div>
    <h2>@{}测试</h2>
    <a th:href="@{http://baidu.com}">百度</a>
    <h2>带参数</h2>
    <a th:href="@{http://baidu.com(name='java',age=23)}">百度(带参数)</a>
</div>

<div>
    <h2>引用fragment</h2>
    <div th:replace="month/my_fragment.html"></div>

    <hr>
    <div th:replace="~{month/my_fragment.html::weibo_link}"></div>

    <hr>
    <div th:replace="~{month/my_fragment.html::baidu_link}"></div>
</div>

<div th:text="true">

</div>

<div>
    <h2>拼接</h2>
    <div th:text="'hello'+${lucky.code}">

    </div>
    <div th:text="|hello,${lucky.code}|"></div>
</div>

<div>
    <h2>算术运算符</h2>
    <div th:with="age=(99*99/99+99-1)">
        <div th:text="${age}"></div>

        <div th:text="9 eq 9 or 8 ne 8"></div>
        <div th:text="!(9 eq 9 or 8 ne 8)"></div>
        <div th:text="not(9 eq 9 or 8 ne 8)"></div>
        <hr>
        <h2>比较和相等</h2>
        <div th:text="${age} eq 197"></div>
        <div th:text="${age} ne 197"></div>
        <div th:text="${age} ge 197"></div>
        <div th:text="${age} gt 197"></div>
        <div th:text="${age} le 197"></div>
        <div th:text="${age} lt 197"></div>
        <hr>
        <h2>三目运算符</h2>
        <div th:text="${age} ne 197 ? 'yes' : 'no'"></div>

    </div>
</div>

<div>
    <h2>基本内置对象</h2>
    <div>#ctx:上下文对象</div>
<!--    <div th:text="${#ctx}"></div>-->
    <div>#vars:上下文变量</div>
    <div>#locale:上下文区域设置</div>
    <div>#request:(仅在web上下文中)HttpServletRequest对象</div>
    <div>#response:(仅在web上下文中)HttpServletRespose对象</div>
    <div>#session:(仅在web上下文中)HttpSession对象</div>
    <div>#servletContext:(仅在web上下文中)ServletContext对象</div>

    <div th:text='${#session}'></div>
<!--    <div th:text='${#session.getAttribute("name")}'></div>-->

</div>
<hr>
<div>
    <h2>实用内置对象</h2>
    <div>#execInfo:有关正在处理的模板的信息</div>
    <div>#messages:在变量表达式中获取外部化消息的方法,与使用#{...}语法获得的方式相同</div>
    <div>#uris:转义URL/.URL部分的方法</div>
    <div>#conversions:执行配置的转换服务(如果有)的方法</div>
    <div>#dates:java.util.Date对象的方法:格式化,组件提取等</div>
    <div>#calendars:类似于#dates,但是java.util.Calendar对象</div>
    <div>#numbers:用于格式化数字对象的方法</div>
    <div>#strings:String对象的方法:contains,startWith,prepending,appending等</div>
    <div>#objects:一般对象的方法</div>
    <div>#bools:布尔评估的方法</div>
    <div>#arrays:数组方法</div>
    <div>#lists:列表的方法</div>
    <div>#sets:集合的方法</div>
    <div>#maps:映射的方法</div>
    <div>#aggregatest:在数组或集合上创建聚合的方法</div>
    <div>#ids:处理可能重复的id属性的方法(例如,作为迭代的结果)</div>
    <hr>
    <h2>例子</h2>
    <div th:text="${#execInfo.getProcessedTemplateName()}"></div>
    <div th:text="${#arrays.length(#request.getAttribute('names'))}"></div>
</div>
<hr>
<div>
    <h2>设置属性值</h2>
    <img th:attr="src=@{/1.png},alt=${lucky.code},title=${lucky.name}">
    <img th:src="@{/1.png}" th:alt="${lucky.code}" title="${lucky.name}">
    <img th:src="@{/1.png}" th:alt-title="${lucky.name}">
</div>
<hr>
<div>
    <h2>遍历 th:each</h2>
    <table border="1">
        <tr th:each="lucky,state:${luckyList}">
            <td th:text="${lucky.code}"></td>
            <td th:text="${state.index}"></td>
            <td th:text="${state.count}"></td>
            <td th:text="${state.size}"></td>
            <td th:text="${state.current}"></td>
            <td th:text="${state.even}"></td>
            <td th:text="${state.odd}"></td>
            <td th:text="${state.first}"></td>
            <td th:text="${state.last}"></td>
        </tr>
    </table>
    <h2>分支语句 th:if</h2>
    <table border="1">
        <tr th:each="lucky,state:${luckyList}" th:if="${state.odd}">
            <td th:text="${lucky.code}"></td>
            <td th:text="${lucky.name}"></td>
            <td th:text="${state.index}"></td>
            <td th:text="${state.count}"></td>
            <td th:text="${state.size}"></td>
            <td th:text="${state.current}"></td>
            <td th:text="${state.even}"></td>
            <td th:text="${state.odd}"></td>
            <td th:text="${state.first}"></td>
            <td th:text="${state.last}"></td>
        </tr>
    </table>
    <h2>分支语句 th:unless</h2>
    <table border="1">
        <tr th:each="lucky,state:${luckyList}" th:unless="${state.odd}">
            <td th:text="${lucky.code}"></td>
            <td th:text="${lucky.name}"></td>
            <td th:text="${state.index}"></td>
            <td th:text="${state.count}"></td>
            <td th:text="${state.current}"></td>
            <td th:text="${state.even}"></td>
            <td th:text="${state.odd}"></td>
            <td th:text="${state.first}"></td>
            <td th:text="${state.last}"></td>
        </tr>
    </table>

    <h2>分支语句:switch</h2>
    <table border="1">
        <tr th:each="lucky,state:${luckyList}">
            <td th:text="${lucky.code}"></td>
            <td th:text="${lucky.name}"></td>
            <td th:text="${state.index}"></td>
            <td th:text="${state.count}"></td>
            <td th:text="${state.current}"></td>
            <td th:text="${state.even}"></td>
            <td th:text="${state.odd}"></td>
            <td th:text="${state.first}"></td>
            <td th:text="${state.last}"></td>
            <td th:switch="${state.odd}">
                <span th:case="true">odd</span>
                <span th:case="*">even</span>
            </td>
        </tr>
    </table>
    <h3>备注:th:case="*",表示默认选项</h3>
</div>

<div>
    <h2>内联</h2>
    <div>
        hello,[[${lucky.code}]]
        <h3>会对html进行转义</h3>
    </div>
    <div>
        hello,[(${lucky.name})]
        <h3>不会对html进行转义</h3>
    </div>
</div>


</body>
</html>